package Or

import (
	"fmt"
	"db2s/ETL"
	"db2s/global"
)

type Instance struct{}

func (i Instance) Position(s global.Position) (any, error) {
	var (
		event       = "[Position]"
		position    string
		execTimeout int64
		err         error
	)
	active := ETL.InstanceActiveS{DBType: DBType, DB: s.Base.Db["single"], StopTime: s.SqlExecStopTime, SqlMode: true}
	//获取当前位点
	strSql := fmt.Sprintf("SELECT CURRENT_SCN FROM V$DATABASE")
	var f1 any
	if execTimeout, f1, err = active.SqlQuery(strSql, ETL.String); err != nil {
		vlog = fmt.Sprintf("%v The execution of a sql statement failed. sql is {%v},error is {%v}", event, strSql, err)
		WLog.Error(vlog)
		return 0, err
	} else {
		position = fmt.Sprintf("%v", *f1.(*string))
	}
	vlog = fmt.Sprintf("%v A sql statement was executed successfully. sql is {%v}, exec timeout is {%vms}", event, strSql, execTimeout)
	WLog.Debug(vlog)
	if len(position) == 0 {
		vlog = fmt.Sprintf("%s The global position query of table a is fail. position is {%v}", event, 0)
		WLog.Warn(vlog)
		return 0, nil
	}
	vlog = fmt.Sprintf("%s The global position query of table a is successful. position is {%v}", event, position)
	WLog.Info(vlog)
	return position, nil
}
